<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .active {
      text-decoration: underline;
    }
    .error {
      color: tomato;
    }
    .transition {
      color: tomato;
    }
    .transition:hover {
      color: teal;
    }
  </style>
</head>
<body>
  <div id="app">
    <h1>通过数组语法控制class&控制style</h1>
    <p v-bind:class="[activeClass, errorClass]">1.数组语法控制class的值</p>
    <p v-bind:class="[isActive?'active': '', errorClass]">
      2.数组语法控制class的值-三元表达式
      <button v-on:click="changeClass">toggle</button>
    </p>
    <p v-bind:class="[{active: isActive}, errorClass, 'active']">
      3.数组语法控制class的值-数组套对象
      <button v-on:click="changeClass">toggle</button>
    </p>
    <hr>
    <hr>
    <p :style="{fontSize:size+'px', color: fontColor}">通过v-bind控制style</p>
    <p :style="styleObj">通过v-bind控制style-解耦</p>
    <p :style="[styleObj, otherStyleObj]">通过v-bind控制style-数组语法</p>
    <p class="transition" :style="{transition:time}">通过v-bind控制style-自动添加前缀</p>
    <input type="text" v-model="size">
  </div>
  <script src="../js/vue.js"></script>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        activeClass: 'active',
        errorClass: 'error',
        isActive: true,
        size: '20',
        fontColor: '#56a5f1',
        styleObj: {
          fontSize:'20px', 
          color: '#56a5f1'
        },
        otherStyleObj: {
          fontWeight: '900',
          fontStyle: 'italic'
        },
        time: '2s'
      },
      methods: {
        changeClass: function(){
          this.isActive = !this.isActive
        }
      },
    })
  </script>
</body>
</html>